<?php
	if(!defined('BASEPATH'))
		exit('No direct script access allowed');

	class m_AdminBills extends CI_Model
	{
		function __construct()
    	{
    	    // Call the Model constructor
    	    parent::__construct();
    	}
		
		function get_bills()
		{
			$this->load->database();
			$this->load->library('Datatables'); 
			$this->datatables->select('invoiceNumber, Vendor, AccountNumber, Name, DueDate, Amount, State')->from('tblBills');
			$query = $this->datatables->generate();
			return $query;
		}
		
		function set_invoice($value, $key)
		{
			$key = explode(":", $key);
			$this->load->database();
			
			$data = array(
						   'invoiceNumber' => $value
						);

			$this->db->where('invoiceNumber', $key[0]);
			$this->db->where('Vendor', $key[1]);
			$this->db->update('tblBills', $data); 
		}
		
		function set_vendor($value, $key)
		{
			$key = explode(":", $key);
			$this->load->database();
			
			$data = array(
						   'Vendor' => $value
						);

			$this->db->where('invoiceNumber', $key[0]);
			$this->db->where('Vendor', $key[1]);
			$this->db->update('tblBills', $data); 
		}
		
		function set_customeraccount($value, $key)
		{
			$key = explode(":", $key);
			$this->load->database();
			
			$data = array(
						   'AccountNumber' => $value
						);

			$this->db->where('invoiceNumber', $key[0]);
			$this->db->where('Vendor', $key[1]);
			$this->db->update('tblBills', $data); 
		}
		
		function set_customername($value, $key)
		{
			$key = explode(":", $key);
			$this->load->database();
			
			$data = array(
						   'Name' => $value
						);

			$this->db->where('invoiceNumber', $key[0]);
			$this->db->where('Vendor', $key[1]);
			$this->db->update('tblBills', $data); 
		}
		
		function set_duedate($value, $key)
		{
			$key = explode(":", $key);
			$this->load->database();
			
			$data = array(
						   'DueDate' => $value
						);

			$this->db->where('invoiceNumber', $key[0]);
			$this->db->where('Vendor', $key[1]);
			$this->db->update('tblBills', $data); 
		}
		
		function set_amount($value, $key)
		{
			$key = explode(":", $key);
			$this->load->database();
			
			$data = array(
						   'Amount' => $value
						);

			$this->db->where('invoiceNumber', $key[0]);
			$this->db->where('Vendor', $key[1]);
			$this->db->update('tblBills', $data); 
		}
		
		function set_status($value, $key)
		{
			$key = explode(":", $key);
			$this->load->database();
			
			$data = array(
						   'State' => $value
						);

			$this->db->where('invoiceNumber', $key[0]);
			$this->db->where('Vendor', $key[1]);
			$this->db->update('tblBills', $data); 
		}
		
		function delete_invoice($invoice, $vendor)
		{
			$this->load->database();
			$this->db->where('invoiceNumber', $invoice);
			$this->db->where('Vendor', $vendor);
			$this->db->delete('tblBills'); 
		}
	}
?>
